package com.example.demo.modules.redis.controller;

import cn.hutool.log.StaticLog;
import com.example.demo.common.util.R;
import com.example.demo.common.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    RedisUtil redisUtil;
    @Autowired
    RedisTemplate redisTemplate;

    @RequestMapping("/get/{key}")
    public R get(@PathVariable String key) {
        Object o = redisUtil.get(key);
        StaticLog.info("redis 查询结果========>{}   ", o);
        return R.ok().put("value", o);
    }
    @RequestMapping("/getAllKey")
    public R getAllKey() {
        Set<String> keys = redisTemplate.keys("*");

        return R.ok().put("value", keys);
    }
}

